<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-row layui-col-space5">
                <div class="layui-col-md8">
                <table class="layui-hide"  id="main-table" lay-filter="main-table"></table>
                </div>
                <div class="layui-col-md4">
                    <fieldset class="layui-elem-field">
                        <legend>预览题目</legend>
                        <div class="layui-field-box">

                        </div>
                    </fieldset>
                </div>
            </div>
        </div>
    </div>
</div>


<script th:inline="none"></script>
<script>
    let recordId = `[[${id}]]`;
    layui.use(['table','form','upload'], function(){
        var table = layui.table,
            form = layui.form;
        table.render({
            elem: '#main-table'
            ,height: 600
            ,url: 'libQuestion/getPageList'
            ,title: '题目列表',
            where:{recordId:recordId,sortField:'orderno'}
            ,limit:20
            ,page: true
            ,cols: [
                [
                    {type: 'checkbox'}
                    ,{field: 'code', title: "编号",width:90}
                    ,{field: 'chapterName', title: "教材/章节",width:220,templet:function(d){
                        return "<a class='colum-link' href='javascript:void(0)' onclick='edit(\""+d.id+"\",\"" + d.chapterName + "\" , this)'>" + d.chapterName + "</a>";
                    }}
                    ,{field: 'text', title: "题干"}
                    ,{field: 'orderno',title: "排序",width:120}
                    ,{field: 'questionTypeTxt',title: "题型",width:120}

                ]
            ]
            ,done:function(){
                enableRowClick(table,form,'main-table',"main-table",'selectQuestion');
            }
        });
        window.loadGrid = function(tableName){
            table.reload(tableName);
        }
        window.selectQuestion = function (){
            var checkStatus = table.checkStatus('main-table');
            let text = checkStatus.data[0].text;
            $(".layui-field-box").html(text);
            let url = "libChoice/getPageList?limit=10&page=1&questionId="+checkStatus.data[0].id;
            if(checkStatus.data[0].delFlag==1){
                url += "&delFlag=1"
            }
            axios.get(url).then(function (res){
                let list = res.data.data;
                if(list.length>0){
                    $(".layui-field-box").append("<hr style='height: 5px;border: none;border-top: 5px double green'>")
                }
                for(var i=0;i<list.length;i++){
                    $(".layui-field-box").append(list[i].indexLetter+". "+list[i].text);
                }
            });
        }
    });
    function edit(id,cid){
        let lq = getEntityInfo(id,"libQuestion/getById")
        top.layer.open({
            id:"editwin",
            type: 2,
            title:'修改题目',
            area:['1500px','880px'],
            content:  'rooter?url=ksxt/lib/add-question1&id='+id+"&delFlag="+lq.delFlag,
            btn:['保存','关闭'],
            yes:function(index,layero){
                var dataForm = top.layer.getChildFrame('form', index);
                dataForm.find("#submitBtn").click();
                return false
            }
        });
    }

</script>
</body>
</html>